'use strict';
const bcrypt = require('bcryptjs');
const moment = require('moment');

/** @type {import('sequelize-cli').Migration} */
module.exports = {
  async up(queryInterface, Sequelize) {
    /**
     * Add seed commands here.
     *
     * Example:
     * await queryInterface.bulkInsert('People', [{
     *   name: 'John Doe',
     *   isBetaMember: false
     * }], {});
     */
    try {
      await queryInterface.bulkInsert('Users', [
        {
          email: 'admin@qq.com',
          username: 'admin',
          password: bcrypt.hashSync('123123', 10),
          nickname: '茶几管理员',
          sex: 2,
          role: 100,
          createdAt: new Date(),
          updatedAt: new Date(),
        },
        {
          email: 'user1@qq.com',
          username: 'user1',
          password: bcrypt.hashSync('123123', 10),
          nickname: '普通用户1',
          sex: 0,
          role: 0,
          createdAt: new Date(),
          updatedAt: new Date(),
        },
        {
          email: 'user2@qq.com',
          username: 'user2',
          password: bcrypt.hashSync('123123', 10),
          nickname: '普通用户1',
          sex: 0,
          role: 0,
          createdAt: new Date(),
          updatedAt: new Date(),
        },
        {
          email: 'member@qq.com',
          username: 'member',
          password: bcrypt.hashSync('123123', 10),
          nickname: '大会员用户',
          sex: 1,
          role: 1,
          membershipExpiredAt: moment().add(1, 'year').toDate(),
          createdAt: new Date(),
          updatedAt: new Date(),
        },
      ]);
    } catch (error) {
      console.log(error);
    }
  },

  async down(queryInterface, Sequelize) {
    /**
     * Add commands to revert seed here.
     *
     * Example:
     * await queryInterface.bulkDelete('People', null, {});
     */
    await queryInterface.bulkDelete('Users', null, {});
  },
};
